/**
 *      AboutWindow.java
 *
 *  This file is part of the PDFGen Syllabus Formatter Project.
 *  Copyright (C) 2011
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.dlsu.pdfgen.gui;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 * The 'About' window showing the details of the project.
 *
 * @author Kevin See
 *
 */
public class AboutWindow extends JFrame{
        // TODO: Add documentation for the class attributes.

        private JLabel jLabel1;
        private JLabel jLabel2;
        private JLabel jLabel3;
        private JLabel jLabel4;
        private JLabel jLabel5;
        private JLabel jLabel6;
        private JLabel jLabel7;
        private JLabel licenseLabel;
        private JLabel projectHomeLabel;
        private JLabel projectLeaderLabel;
        private JScrollPane projectMembers;
        private JTextArea projectMembersArea;
        private JFrame ftemp;
        /**
         * Constructor for the About window.
         */
        public AboutWindow(JFrame frame) {
                initComponents();
                setVisible(true);
                ftemp = frame;
                ftemp.setEnabled(false);
                setLocationRelativeTo(null);
                addWindowListener(new java.awt.event.WindowAdapter()   
              {  
                public void windowClosing(java.awt.event.WindowEvent e )   
                { 
                        ftemp.setEnabled(true);
                }
              }
                );
                readProjectMembers();
        }
        
        /**
         * Reads the file "ProjectMembers.txt" which contains all the members of the
         * project. Outputs the contents of "ProjectMembers.txt" to the About
         * window.
         */
        
        private void readProjectMembers() {

                InputStream projectMembersFile = getClass().getResourceAsStream(
                                ("/org/dlsu/pdfgen/resources/ProjectMembers.txt"));

                if (projectMembersFile != null) {
                        String text = null;

                        try {
                                BufferedReader reader = new BufferedReader(
                                                new InputStreamReader(projectMembersFile));
                                while ((text = reader.readLine()) != null) {
                                        projectMembersArea.setText(projectMembersArea.getText()
                                                        + text + "\n");
                                }
                        } catch (FileNotFoundException e) {
                                System.err.println("Unable to locate ProjectMembers.txt.");
                                e.printStackTrace();
                        } catch (IOException e) {
                                System.err.println("Unable to read ProjectMembers.txt.");
                                e.printStackTrace();
                        }

                } else {
                        System.out.println("Cannot locate ProjectMembers.txt.");
                }
        }
        

        /**
         * Initializes all components before launching the window.
         */
        private void initComponents() {

                jLabel1 = new javax.swing.JLabel();
                jLabel2 = new javax.swing.JLabel();
                jLabel3 = new javax.swing.JLabel();
                jLabel4 = new javax.swing.JLabel();
                jLabel5 = new javax.swing.JLabel();
                jLabel6 = new javax.swing.JLabel();
                projectLeaderLabel = new javax.swing.JLabel();
                projectHomeLabel = new javax.swing.JLabel();
                licenseLabel = new javax.swing.JLabel();
                jLabel7 = new javax.swing.JLabel();
                projectMembers = new javax.swing.JScrollPane();
                projectMembersArea = new javax.swing.JTextArea();

                setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
                setTitle("About");
                setResizable(false);

                jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource(
                                "/org/dlsu/pdfgen/resources/DLSU-Manila_Seal.png"))); // NOI18N

                jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource(
                                "/org/dlsu/pdfgen/resources/CCS-logo.png"))); // NOI18N

                jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
                jLabel3.setText("Syllabus Formatter");

                jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
                jLabel4.setText("Project Leader:");

                jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
                jLabel5.setText("Project Home:");

                jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
                jLabel6.setText("License:");

                projectLeaderLabel.setText("Professor Gian Fontanilla");

                projectHomeLabel
                                .setText("http://code.google.com/p/opensrc-syllabus-formatter/");

                licenseLabel.setText("GPLv3");

                jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
                jLabel7.setText("Project Members:");

                projectMembersArea.setColumns(20);
                projectMembersArea.setEditable(false);
                projectMembersArea.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
                projectMembersArea.setRows(5);
                projectMembers.setViewportView(projectMembersArea);

                javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
                                getContentPane());
                getContentPane().setLayout(layout);
                layout
                                .setHorizontalGroup(layout
                                                .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(
                                                                layout
                                                                                .createSequentialGroup()
                                                                                .addContainerGap()
                                                                                .addGroup(
                                                                                                layout
                                                                                                                .createParallelGroup(
                                                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                .addGroup(
                                                                                                                                layout
                                                                                                                                                .createSequentialGroup()
                                                                                                                                                .addComponent(
                                                                                                                                                                jLabel1)
                                                                                                                                                .addPreferredGap(
                                                                                                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                                                                .addComponent(
                                                                                                                                                                jLabel2)
                                                                                                                                                .addPreferredGap(
                                                                                                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                                                                .addComponent(
                                                                                                                                                                jLabel3))
                                                                                                                .addGroup(
                                                                                                                                layout
                                                                                                                                                .createSequentialGroup()
                                                                                                                                                .addGap(
                                                                                                                                                                10,
                                                                                                                                                                10,
                                                                                                                                                                10)
                                                                                                                                                .addGroup(
                                                                                                                                                                layout
                                                                                                                                                                                .createParallelGroup(
                                                                                                                                                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                                                                                                                                                .addComponent(
                                                                                                                                                                                                jLabel5)
                                                                                                                                                                                .addComponent(
                                                                                                                                                                                                jLabel4)
                                                                                                                                                                                .addComponent(
                                                                                                                                                                                                jLabel7)
                                                                                                                                                                                .addComponent(
                                                                                                                                                                                                jLabel6))
                                                                                                                                                .addPreferredGap(
                                                                                                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                                                                .addGroup(
                                                                                                                                                                layout
                                                                                                                                                                                .createParallelGroup(
                                                                                                                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                                                                                .addComponent(
                                                                                                                                                                                                projectMembers,
                                                                                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                                                                                262,
                                                                                                                                                                                                Short.MAX_VALUE)
                                                                                                                                                                                .addGroup(
                                                                                                                                                                                                layout
                                                                                                                                                                                                                .createParallelGroup(
                                                                                                                                                                                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                                                                                                                                                                                false)
                                                                                                                                                                                                                .addComponent(
                                                                                                                                                                                                                                projectHomeLabel,
                                                                                                                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                                                                                                                Short.MAX_VALUE)
                                                                                                                                                                                                                .addComponent(
                                                                                                                                                                                                                                projectLeaderLabel))
                                                                                                                                                                                .addComponent(
                                                                                                                                                                                                licenseLabel))))
                                                                                .addContainerGap()));
                layout
                                .setVerticalGroup(layout
                                                .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(
                                                                layout
                                                                                .createSequentialGroup()
                                                                                .addGroup(
                                                                                                layout
                                                                                                                .createParallelGroup(
                                                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                .addGroup(
                                                                                                                                layout
                                                                                                                                                .createSequentialGroup()
                                                                                                                                                .addContainerGap()
                                                                                                                                                .addGroup(
                                                                                                                                                                layout
                                                                                                                                                                                .createParallelGroup(
                                                                                                                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                                                                                .addComponent(
                                                                                                                                                                                                jLabel2)
                                                                                                                                                                                .addComponent(
                                                                                                                                                                                                jLabel1)))
                                                                                                                .addGroup(
                                                                                                                                layout
                                                                                                                                                .createSequentialGroup()
                                                                                                                                                .addGap(
                                                                                                                                                                41,
                                                                                                                                                                41,
                                                                                                                                                                41)
                                                                                                                                                .addComponent(
                                                                                                                                                                jLabel3)))
                                                                                .addPreferredGap(
                                                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                                .addGroup(
                                                                                                layout
                                                                                                                .createParallelGroup(
                                                                                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                                                                                .addComponent(jLabel4)
                                                                                                                .addComponent(
                                                                                                                                projectLeaderLabel))
                                                                                .addPreferredGap(
                                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                .addGroup(
                                                                                                layout
                                                                                                                .createParallelGroup(
                                                                                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                                                                                .addComponent(jLabel5)
                                                                                                                .addComponent(
                                                                                                                                projectHomeLabel))
                                                                                .addPreferredGap(
                                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                .addGroup(
                                                                                                layout
                                                                                                                .createParallelGroup(
                                                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                .addComponent(jLabel7)
                                                                                                                .addComponent(
                                                                                                                                projectMembers,
                                                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                                                .addPreferredGap(
                                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                .addGroup(
                                                                                                layout
                                                                                                                .createParallelGroup(
                                                                                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                                                                                .addComponent(
                                                                                                                                licenseLabel)
                                                                                                                .addComponent(jLabel6))
                                                                                .addContainerGap(
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                Short.MAX_VALUE)));

                pack();
        }

}
